#include "CSpawnSystem.h"
#include "Enemy.h"
#include "BasicEnemy.h"
#include "BossStage1.h"
#include "BossStage2.h"
#include "FlyingEnemy.h"
#include "ShootingEnemy.h"
#include "JumperEnemy.h"

CSpawnSystem::CSpawnSystem(void)
{
}


CSpawnSystem::~CSpawnSystem(void)
{
}

CSpawnSystem* CSpawnSystem::GetInstance(void)
{
	static CSpawnSystem s_Instance;
	return &s_Instance;
}

bool CSpawnSystem::Spawn(CEntity* pTarget,string type, int numberof,int x,int y,int speedOffset)
{
	
	m_pOF = CObjectFact::GetInstance();
	m_pOM = CObjectManager::GetInstance();
	pTarget->SetType(OBJ_PLAYER);
	for(int e =0;e<numberof;e++)
	{
	if(type=="Test"||type=="Base")
	{
		//CPlayer* pPlayer = dynamic_cast<CPlayer*>(pTarget);
		
		m_pOF->RegisterClassType<CBasicEnemy>(L"CBasicEnemy");		

		CEntity*  DEnemy = m_pOF->CreateObject(L"CBasicEnemy");
			CBasicEnemy* pEnemy = dynamic_cast<CBasicEnemy*>(DEnemy);
			if(pEnemy->Init(pTarget,x,y,speedOffset))
			{
				m_pOM->AddObject(pEnemy);
				pEnemy->Release();
			}
			else
				return false;
	}
	if(type=="Flyer")
	{
		m_pOF->RegisterClassType<CFlyingEnemy>(L"CFlyingEnemy");		
	
		CEntity*  DEnemy = m_pOF->CreateObject(L"CFlyingEnemy");
			CEnemy* pEnemy = dynamic_cast<CFlyingEnemy*>(DEnemy);
				m_pOM->AddObject(pEnemy);
				pEnemy->Release();
	}
	if(type=="Jumper")
	{
		m_pOF->RegisterClassType<CJumperEnemy>(L"CJumperEnemy");		
		CEntity*  DEnemy = m_pOF->CreateObject(L"CJumperEnemy");
			CEnemy* pEnemy = dynamic_cast<CJumperEnemy*>(DEnemy);
			if(pEnemy->Init(pTarget,x,y,speedOffset))
			{
				m_pOM->AddObject(pEnemy);
				pEnemy->Release();
			}
				else
				return false;
	}
	if(type=="Shooter")
	{

		m_pOF->RegisterClassType<CShootingEnemy>(L"CShootingEnemy");		
		CEntity*  DEnemy = m_pOF->CreateObject(L"CShootingEnemy");
			CEnemy* pEnemy = dynamic_cast<CShootingEnemy*>(DEnemy);
			if(pEnemy->Init(pTarget,x,y,speedOffset))
			{
				m_pOM->AddObject(pEnemy);
				pEnemy->Release();
			}
				else
				return false;
	}
	if(type=="Boss1")
	{
		m_pOF->RegisterClassType<CBossStage1>(L"CBossStage1");		
		CEntity*  DEnemy = m_pOF->CreateObject(L"CBossStage1");
			CEnemy* pEnemy = dynamic_cast<CBossStage1*>(DEnemy);
			if(pEnemy->Init(pTarget,x,y,speedOffset))
			{
				m_pOM->AddObject(pEnemy);
				pEnemy->Release();
			}
				else
				return false;
	}
	if(type=="Boss2")
	{
		m_pOF->RegisterClassType<CBossStage2>(L"CBossStage2");		
		CEntity*  DEnemy = m_pOF->CreateObject(L"CBossStage2");
			CEnemy* pEnemy = dynamic_cast<CBossStage2*>(DEnemy);
			if(pEnemy->Init(pTarget,x,y,speedOffset))
			{
				m_pOM->AddObject(pEnemy);
				pEnemy->Release();
			}
				else
				return false;
	}
	

	}

	return true;
}